/**
 * Reads root directory from server and puts in into model.
 */
function main() {
		// get root folder
		var rootFolder = roothome.childByNamePath(url.extension);
		
		// get summary object
		var rootObj=summarizeObject(rootFolder,url.server);

		// stringify root folder
		var jsonString = jsonUtils.toJSONString(rootObj);
		model.jsonString = jsonString;
}

/**
 * Retrieves the necessary properties of the alfresco node and creates a new
 * summary object that is suitable to stringify.
 * 
 * @param alfNode alfresco node.
 * @return summary object that is suitable to stringify.
 */
function summarizeObject(alfNode,urlServer) {
	// object to stringify
	var rootObj = {};
	
	// get necessary properties
	rootObj.name = alfNode.properties.name;
	rootObj.type = alfNode.type;
	rootObj.nodeRef = alfNode.nodeRef;
	rootObj.urlServer = urlServer;
	//rootObj.refcodepart = alfNode.properties["{http://www.alfresco.org/model/recordsmanagement/1.0}ts13298RefCodePart"];

	// recursively get children objects
	var children=new Array();
	if (alfNode.children.length > 0) {
		var temp=0;
		for ( var child in alfNode.children) {
			//children[temp]=summarizeObject(alfNode.children[temp]);
			var a = {};
			//alfNode.children[temp].properties.encoding ="UTF-8";
			a.name 			= alfNode.children[temp].properties.name;
			a.type 			= alfNode.children[temp].type;
			a.nodeRef 		= alfNode.children[temp].nodeRef;
			a.urlServer 	= urlServer;
			a.children	= null;
			children[temp]=a; //summarizeObject(alfNode.children[temp]);
			temp=temp+1;
		}
	}
	rootObj.children=children;
	
	// return summary 
	return rootObj;
}

main();